<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>炫彩边框</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        *,
        *::before,
        *::after {
            box-sizing: border-box;
        }

        @keyframes rotate {
            100% {
                transform: rotate(1turn);
            }
        }

        .rainbow {
            position: relative;
            z-index: 0;
            width: 400px;
            height: 300px;
            border-radius: 10px;
            /*此乃障眼法， 去掉这个属性就比较好理解实现原理了 */

            overflow: hidden;

            padding: 2rem;
        }

        .rainbow::before {
            content: '';
            position: absolute;
            z-index: -2;
            left: -50%;
            top: -50%;
            width: 200%;
            height: 200%;
            background-color: #399953;
            background-repeat: no-repeat;
            background-size: 50% 50%, 50% 50%;
            background-position: 0 0, 100% 0, 100% 100%, 0 100%;
            background-image: linear-gradient(#399953, #399953), linear-gradient(#fbb300, #fbb300), linear-gradient(#d53e33, #d53e33), linear-gradient(#377af5, #377af5);
            animation: rotate 4s linear infinite;
        }

        @keyframes opacityChange {
            50% {
                opacity: 1;
            }

            100% {
                opacity: .5;
            }
        }
    </style>
</head>

<body>

    <div class="rainbow"></div>
</body>

</html>